from rest_framework import serializers
from .models import Log


class LogSerializer(serializers.ModelSerializer):
    def to_representation(self, instance):
        data = super().to_representation(instance)
        data['user'] = None
        if instance.user:
            data['user'] = {
                'id': instance.user.id,
                'username': instance.user.username,
                'name': instance.user.name
            }
        return data

    class Meta:
        model = Log
        fields = '__all__'
